// Author: wsfuyibing <682805@qq.com>
// Date: 2025-04-28

package maps

import (
	"context"
	"server/app/config"
	"server/app/kind"
	"server/app/lib/maps/amap"
	"server/app/lib/maps/i"
)

type (
	Manager  = i.Manager
	Location = i.Location

	manager struct {
		plugin Manager
	}
)

func New() Manager {
	return (&manager{}).init()
}

// +---------------------------------------------------------------------------+
// | Interface methods                                                         |
// +---------------------------------------------------------------------------+

func (o *manager) GetAddressByLocation(ctx context.Context, latitude, longitude kind.GeoPoint) (loc i.Location, err error) {
	return o.plugin.GetAddressByLocation(ctx, latitude, longitude)
}

// +---------------------------------------------------------------------------+
// | Hook methods                                                              |
// +---------------------------------------------------------------------------+

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *manager) init() *manager {
	switch config.Maps.GetType() {
	case "amap":
		o.plugin = amap.New()
	}
	return o
}
